package com.xinzhi.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.xinzhi.mapper.BonusreviewMapper;
import com.xinzhi.pojo.dto.Bonusreview;
import com.xinzhi.service.BonusreviewServicee;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 特殊加分审核根据年份查询接口
 */
@Service
public class BonusreviewServiceeImpl implements BonusreviewServicee {
    @Autowired
    private BonusreviewMapper bonusreviewMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Override
    public Result selectBonusreview(Integer yearnumber) {
        String o =(String) redisUtils.get("bonusreview" + yearnumber);
        if (StrUtil.isNotBlank(o)) {
            return Result.ok(o);
        }
        List<Bonusreview> bonusreviews = bonusreviewMapper.selectBonusreview(yearnumber);
        if (bonusreviews.size() == 0){
            return Result.error("没有数据");
        }
        redisUtils.set("bonusreview" + yearnumber, JSONUtil.toJsonStr(bonusreviews));
        return Result.ok(bonusreviews);
    }
}

